const components = require.context('./common', false, /\.vue$/)
import { createApp } from 'vue'
export default {
  install(app) {
    let cs = components.keys()
    cs.forEach((item) => {
      let c = components(item).default
      app.component(c.name, c)
    })
    // 自定义loading
    let loadComp = null
    app.config.globalProperties.$showLoading = () => {
      loadComp = createApp({
        render: () => (
          <div id="loading">
            <span></span>
            <span></span>
          </div>
        )
      })
      loadComp.mount('#root')
    }
    app.config.globalProperties.$hideLoading = () => loadComp.unmount()

    app.mixin({
      methods: {
        filterNum(n) {
          return n < 1000 ? n : ~~(n / 1000) + 'k'
        }
      }
    })
  }
}
